const path = require('path')
const HtmlWebpackPlugin = require('html-webpack-plugin')
const { VueLoaderPlugin } = require('vue-loader')

module.exports = {
  entry: './src/app.js',
  output: {
    // path写成绝对路径
    path: path.resolve(__dirname, 'dist'),
    filename: 'bundle.js'
  },
  // 配置webpack-dev-server
  devServer: {
    open: true,
    port: 8888,
  },
  module: {
    rules: [
      {
        test: /\.css$/i,
        // 处理顺序是从右到左
        use: ["style-loader", "css-loader"],
      },
      {
        test: /\.less$/i,
        use: ["style-loader","css-loader","less-loader",],
      },
      {
        test: /\.s[ac]ss$/i,
        use: ["style-loader","css-loader","sass-loader",],
      },
      {
        test: /\.(png|jpe?g|gif)$/i,
        use: [
          {
            loader: 'url-loader',
            options: {
              // 文件大小限制 如果说大于limit的值 以路径形式展示，如果小于就以base64格式显示
              limit: 8192,
            },
          },
        ],
      },
      {
        test: /\.vue$/,
        loader: 'vue-loader'
      }
    ],
  },
  plugins: [
    new HtmlWebpackPlugin({
      template: './public/index.html',
      filename: 'index.html'
    }),
    new VueLoaderPlugin()
  ],
  mode: 'development'
}